import { getCategoryListData, getGoodsListData } from '@/service/product/product'
import type { IGoodsList } from '@/types/main.ts/main'
import { defineStore } from 'pinia'

const useProductStore = defineStore('product', {
  state: () => ({
    goodsList: [] as IGoodsList[],
    goodstotalcount: 0,
    categoryList: [] as any[],
    categorytotalcount: 0
  }),
  actions: {
    // 获取商品列表
    async getGoodsListDataAction(data: any) {
      const goodsListRes = await getGoodsListData(data)
      const { list, totalCount } = goodsListRes.data
      this.goodsList = list
      this.goodstotalcount = totalCount
    },
    // 获取商品分类
    async getCategoryListDataAction(data: any) {
      const categoryListRes = await getCategoryListData(data)
      const { list, totalCount } = categoryListRes.data
      this.categoryList = list
      this.categorytotalcount = totalCount
    }
  }
})

export default useProductStore
